package com.fd.wpx.authorizating.service.impl;

import com.fd.wpx.authorizating.service.SysPrivilegeService;
import com.fd.wpx.blog.mapper.SysPrivilegeMapper;
import com.fd.wpx.blog.pojo.SysPrivilege;
import com.fd.wpx.blog.pojo.SysPrivilegeExample;
import com.fd.wpx.common.pojo.BlogResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class SysPrivilegeServiceImpl implements SysPrivilegeService {
    @Autowired
    private SysPrivilegeMapper sysPrivilegeMapper;
    @Override
    public BlogResult findPrivilegebyId(Integer id) {
        SysPrivilege privilege=sysPrivilegeMapper.selectByPrimaryKey(id);
        BlogResult result=null;
        if(privilege!=null)
        {
            result=BlogResult.build(200,"查询成功",privilege);
        }else
        {
            result=BlogResult.build(404,"没有改权限");
        }
        return result;
    }

    @Override
    public BlogResult findPrivilegebyIds(Integer[] ids) {
        BlogResult result=null;
        SysPrivilegeExample example=new SysPrivilegeExample();
        SysPrivilegeExample.Criteria criteria=example.createCriteria();
        criteria.andIdIn(new ArrayList<Integer>(Arrays.asList(ids)));
        List<SysPrivilege> privileges=sysPrivilegeMapper.selectByExample(example);
        if(privileges.size()>0)
        {
            result=BlogResult.ok(privileges);
        }else
        {
            result=BlogResult.build(404,"未找到数据");
        }
        return result;
    }

    @Override
    public BlogResult updatePrivilege(SysPrivilege privilege) {
        sysPrivilegeMapper.updateByPrimaryKey(privilege);
        return BlogResult.ok();
    }

    @Override
    public BlogResult deletePrivilege(SysPrivilege privilege) {
        sysPrivilegeMapper.deleteByPrimaryKey(privilege.getId());
        return BlogResult.ok();
    }

    @Override
    public BlogResult addPrivilege(SysPrivilege privilege) {
        sysPrivilegeMapper.insert(privilege);
        return BlogResult.ok();
    }
}
